package utility;
import java.net.*;
import java.io.*;


public class LoginThread implements Runnable{
	private ServerSocket ss;
	private Socket s;
	private static int portNo = 2000;
	private String name;
	private String password;
	private boolean isValid;
	private DataInputStream dis;
	private DataOutputStream dos;
	
	public LoginThread(){
		isValid = false;
		try{
			ss = new ServerSocket(portNo);
		}catch(IOException e){
			e.printStackTrace();
			isValid = true;
		}
		portNo++;
		
	}
	
	public void valid(){
		isValid = true;
		try{
			if(ss != null){
				ss.close();
				ss = null;
			}
			if(s != null){
				s.close();
				s = null;
			}
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public String getUserName(){
		return name;
	}
	public String getUserPassword(){
		return password;
	}
	
	public void run(){
		try {
				s = ss.accept();
				dos = new DataOutputStream(s.getOutputStream());
				dis = new DataInputStream(s.getInputStream());
		} catch (IOException e) {
				e.printStackTrace();
		}
			
		while(!isValid){
			try {
				dos.writeUTF("User Account Name: ");
				name = dis.readUTF();
				dos.writeUTF("User PassWord: ");
				password = dis.readUTF();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
		
	}

}
